﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Windows.Forms.DataVisualization.Charting;

namespace ChartForm
{
    public partial class chartForm : Form
    {
        public chartForm()
        {
            InitializeComponent();
        }

        public chartForm(Dictionary<string, Double> chartData_, int month_, Double totalExpense_)
        {
            InitializeComponent();
            foreach(KeyValuePair<string, Double> dataPoint in chartData_)
            {
                chart1.Series["Series1"].Points.AddXY(String.Format("{0} - ${1}", dataPoint.Key, Math.Round(dataPoint.Value, 2)), 
                    Math.Round(dataPoint.Value, 2));
            }
            //set Title
            string titleText = "Expense Report:";
            List<string> months = new List<string>() { 
                                "January", "February", "March", "April", "May", "June",
                                "July", "August", "September", "October", "November", "December" };
            for (int ctr = 0; ctr < months.Count; ctr++)
            {
                if (month_ == ctr)
                {
                    titleText = string.Format("{0} {1}", titleText, months[ctr]);
                }
            }
            //Add total expense to title
            titleText = string.Format("{0} (Total Expense: {1})", titleText, totalExpense_.ToString());
            chart1.Titles["Title1"].Text = titleText;
            
        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }

        /*protected override void OnPaint(PaintEventArgs e)
        {
            float sum = 0.0f;
            foreach (float percentage in m_percentage)
            {
                sum += percentage;
            }

            List<float> anglesInDegrees = new List<float>();
            foreach (float percentage in m_percentage)
            {
                anglesInDegrees.Add((percentage / sum) * 360);
            }

            base.OnPaint(e);
            Graphics graphicsObject = this.CreateGraphics();

            List<SolidBrush> brushes = new List<SolidBrush> 
                { 
                    new SolidBrush(Color.Red), 
                    new SolidBrush(Color.Blue),
                    new SolidBrush(Color.GreenYellow)
                };
            Rectangle newRect = new Rectangle(30, 30, 230, 230);

            float startAngle = 0.0f;
            int index = 0;
            foreach (float sweepAngle in anglesInDegrees)
            {
                graphicsObject.FillPie(brushes[index], newRect, startAngle, sweepAngle);
                startAngle += sweepAngle;
                index++;
            }
            
        }*/
    }
}
